#include "../include/MainHeader.h"


int checkNameValidity(char* fileName) {

	int len = 0;

	
	
	char *tempFile = fileName;
	//tempFile++;

	while(len<strlen(fileName)) {

		if(*tempFile == '/') {
			return 0;
		}
		tempFile++;
		len++;
	}
	
	return 1;
}


char* fetchFileName(char* fileFullPath) {

	char *tempStr = fileFullPath;
	int size=1;
	int index=0;

	while(size<=strlen(fileFullPath)) {

		if(*tempStr == '/'){
			index=size;
		}
		tempStr++;
		size++;
	}
	size=0;
	tempStr = fileFullPath;

	while(size<index) {
		tempStr++;
		size++;
	}
	//printf("\nin utils******\n");
	//printf("\n%s\n", fileFullPath);
	//printf("\n%s\n", tempStr);

	return tempStr;

}




char* parsePath(char *path)
{


	//printf("\npath in parseint=%s\n",path);

	int l,i,j=0,dec=1,k=0;
	char *temp;
	char *pat;
	pat=(char*)malloc(sizeof(char)*50);
	strcpy(pat,"");//*****************************************************************************************
	char tokens[MAX_DIR][MAX_PATH_SIZE];
	temp=(char*)malloc(sizeof(10));			//CHAGE IT
	l=strlen(path);
	for(i=1;i<l;i++)
	{		
		if(dec==1)
		{
			k=0;
			dec=0;
		}	
		if(path[i]=='/')	
		{
			*(temp+k)='\0';
			strcpy(tokens[j],temp);		//Copy the token when you get '/'
			j++;
			dec=1;
		}
		else
		{
			*(temp+k)=path[i];	//Append to temp until '/' in the path
			k++;
		}
	}
	*(temp+k)='\0';
	strcpy(tokens[j],temp);
	strcat(pat,"/");
	for(i=0;i<j;i++){
		strcat(pat,tokens[i]);
		if(i!=j-1)
			{
				strcat(pat,"/");
			}
	}

	//printf("\npath in parseint before return=%s\n",pat);
	return pat;
}
int lastcharcheck(char *path)
{
	char *tempPath = path;
	int len=strlen(tempPath);

	int index=0;
	
	while(index<len-1)
	{
		tempPath++;
		index++;
	}
	
	if(*tempPath=='/')
		return 1;
	else
		return 0;
}
/*
char* removeLastSlash(char *path)
{
	char *temp = (char*)malloc(sizeof(char)*(strlen(path)-1));
	
	strcpy(temp,path);

	//int len = 0;
	//while(len < strlen(path))
	//{
		*temp = *path;
		path++;
		temp++;
		len++;
	}
	return 
}*/
